<!--
 * @Author: 橘子
 * @Project_description: 表单
 * @Description: 代码是我抄的，不会也是真的
-->

<style lang="scss" scoped>
.form-box {
  padding: 20rpx;
  box-sizing: border-box;
  .form-item-box {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }
}

.btn {
  padding: 30rpx 0;
  box-sizing: border-box;
  margin-bottom: 50rpx;
}
.right-icon-box{
  margin-left: 30rpx;
}
</style>
<template>
  <!-- 表单 -->
  <view class="form-box">
    <q-navbar title="订单核销" :isBack="false"></q-navbar>
    <u-form ref="form">
      <u-form-item label="订单号" prop=""  label-width="auto">
        <view class="form-item-box">
          {{ form.order.id }}
        </view>
      </u-form-item>
      <u-form-item label="货物信息" prop="" label-width="auto" label-position="top"  >
        <u-cell-group>
          <u-cell-item  :title="i.sname" :arrow="false" :value="`${i.weight}吨`"  v-for="(i,index) in form.orderConnectList" :key="index">
            <view slot="right-icon" class="right-icon-box">
              X{{i.num}}{{i.unit}}
            </view>
          </u-cell-item>
        </u-cell-group>
      </u-form-item>
      <u-form-item label="物流信息" prop="getTime" label-width="auto" label-position="top">
      <view style="width: 100%">
        <u-form ref="form1">
          <u-form-item label="物流公司" prop=""  label-width="auto">
            <view class="form-item-box">
             {{form.car.panyName}}
            </view>
          </u-form-item>
          <u-form-item label="车牌号" prop=""  label-width="auto">
            <view class="form-item-box">
              {{form.car.name}}
            </view>
          </u-form-item>
          <u-form-item label="车辆类型" prop=""  label-width="auto">
            <view class="form-item-box">
              {{carTypeS}}
            </view>
          </u-form-item>
          <u-form-item label="发货日期" prop=""  label-width="auto">
            <view class="form-item-box">
             {{day(form.transport.parcelTime).format('YYYY-MM-DD')}}
            </view>
          </u-form-item>
        </u-form>
      </view>
      </u-form-item>
      <u-form-item label="收货信息" prop="" label-width="auto" label-position="top">
        <view style="width: 100%">
          <u-form ref="form1">
            <u-form-item label="收货人姓名" prop=""  label-width="auto">
              <view class="form-item-box">
                {{ form.order.receiver }}
              </view>
            </u-form-item>
            <u-form-item label="收货人电话" prop=""  label-width="auto">
              <view class="form-item-box">
                {{ form.order.receivePhone }}
              </view>
            </u-form-item>
            <u-form-item label="收获地址" prop=""  label-width="auto">
              <view class="form-item-box">
                {{form.order.receiveAddress+'-'+form.order.receiveLocation }}
              </view>
            </u-form-item>
          </u-form>
        </view>
      </u-form-item>
    </u-form>
    <view class="btn"  v-if="form.transport.isTime==0">
<!--       v-if="form.order.status==1"-->
      <u-button type="primary" @click="success" >核验收货</u-button>
<!--      v-if="form.order.status==1"-->
      <u-button  plain @click="cn" style="margin-top: 20rpx"  >取消收货</u-button>
    </view>
  </view>
</template>

<script>
import day from 'dayjs'
import api from '@/api/modules/yuanshi.api'
import deepClone from "@/utils/core/deepClone";
export default {
  name: 'form',
  data() {
    return {
      form: {
        order:{},
        orderConnectList:[],
        car:{},
        transport:{},
      },
      id:'',
      carTypeList:[],
    }
  },
  computed: {
    carTypeS(){
      try {
        return  this.carTypeList.find(item=>item.typeId==this.form.car.carType)?.typeName
      }catch (e) {
        return  ''
      }
    }
  },
  methods: {
    day,
    async getDetail(){
      let res=await api.getyunshu(this.id)
      if(res.data&&res.data.records)this.form=res.data.records[0]
      console.log(this.form)
    },
    //类型
    async getTypeList(){
      let res=await  api.typesbyId('lpdnnzkq-1cu3q8z1-hsvi90-0000001')
      this.carTypeList=res.data
    },
    async success(){
      //更新订单信息
      let order=deepClone(this.form.order)
      order.status=2
      await  api.putOrder({order})
      //更新订单信息
      let transport=deepClone(this.form.transport)
      transport.isTime=2
      await  api.putTransport(transport)
      uni.showToast({
        title: '核验成功',
        icon: 'none',
        duration: 2000
      })
      this.getDetail()
    },
    cn(){
      uni.showModal({
        title: '确定取消收货吗？',
        showCancel: true,
        success: (res) => {
          if (res.confirm) {
            uni.showToast({
              title: '取消收货',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })

      //关闭当前页面
    }
  },
  /*uni方法*/
  async onLoad(options) {
    await this.getTypeList()
    this.id=options.id
    await this.getDetail()
  },
  onReady() {
    this.$refs.form.setRules(this.rules);
  },
}
</script>